*****************************************************************************************************************************************************************************************
****************************************************************************Turnout analyses*********************************************************************************************
*****************************************************************************************************************************************************************************************
cd "E:\workdata\704429\Projektfiles\Co-residence"
est clear

use analysis_out_data_all_pairs, clear

**Generate stacked datasæt**
gen id=_n
replace koen1 = koen1 - 1 
replace koen2 = koen2 - 1 

save temp_analysis1.dta, replace
foreach var in stemt residentialstability stemte_2009 pnr FOED_DAG koen  {
	rename `var'1 `var'3
	rename `var'2 `var'1
	rename `var'3 `var'2
}

append using temp_analysis1.dta

lab def koen 0 "male" 1 "female"
lab val koen1 koen
lab val koen2 koen

keep HH_id pnr1 stemte_20091 stemt1 dato1 FOED_DAG1 koen1 residentialstability1

rename (pnr1 stemte_20091 stemt1 dato1 FOED_DAG1 koen1 residentialstability1) ///
(pnr stemte_2009 stemt dato FOED_DAG koen residentialstability)

replace HH_id = HH_id + 10000000

append using disc_analysis_singles.dta

lab val koen koen

duplicates t HH_id, gen(couple) // generate variable for couples

**Generate dates**
gen valg13=dato-19681 // Cont. date 2013
gen month13=floor((valg13-1)/30)+0.5 // 1 month 2013


*****************************************************************************************************************************************************************************************
********************************************************************************************FIGURE S3.1**********************************************************************************
*****************************************************************************************************************************************************************************************

preserve
collapse stemt, by(month13 couple) // Turnout depending on past turnout

graph twoway (scatter stemt month13 if couple == 0 & month13>=-12 & month13<12, ///
mcolor(black) msymbol(Oh)) ///
(scatter stemt month13 if couple == 1 & month13>=-12 & month13<12, ///
mcolor(black) ), ///
 ytitle(Average  turnout) ///
 ylabel(0.40(0.05)0.80)  ///
 xtitle(Months from the election (30 day increments)) ///
 xline(0)  ///
 legend(label(1 Singles) label(2 Couples)) ///
 graphregion(color(white)) ///
 saving(move_single_graphs/figure1_temp2.gph, replace)  
 graph export move_in_graphs/DiD.png, height(600) width(600) replace
 graph export output/DiD.png, height(600) width(600) replace
restore 
